<div class="content-section introduction">
    <div>
        <span class="feature-title">Defer</span>
        <span>Defer directive postpones the loading the content that is initially not in viewport until it becomes visible on scroll. Think of
        pDefer as a smart ngIf that lazily loads content when it becomes visible after page scroll. Scroll down to load the DataTable
        which initiates a query that is not executed on initial page load to speed up load performance.</span>
    </div>
</div>

<div class="content-section implementation">
    <div style="height:800px">
        DataTable is not loaded, scroll down to initialize it.
    </div>
    
    <p-growl [value]="msgs"></p-growl>
    
    <div pDefer (onLoad)="initData()">
        <ng-template>
            <p-dataTable [value]="cars">
                <p-column field="vin" header="Vin"></p-column>
                <p-column field="year" header="Year"></p-column>
                <p-column field="brand" header="Brand"></p-column>
                <p-column field="color" header="Color"></p-column>
            </p-dataTable>
        </ng-template>
    </div>

</div>

<div class="content-section documentation">
    <p-tabView effect="fade">
        <p-tabPanel header="Documentation">
                    <h3>Import</h3>
<pre>
<code class="language-typescript" pCode ngNonBindable>
import &#123;DeferModule&#125; from 'primeng/primeng';
</code>
</pre>

            <h3>Getting Started</h3>
            <p>Defer is applied to a container element with pDefer directive where content needs to be placed inside an ng-template.</p>
<pre>
<code class="language-markup" pCode ngNonBindable>
&lt;div pDefer&gt;
    &lt;ng-template&gt;
       deferred content
   &lt;/ng-template&gt;
&lt;/div&gt;
</code>
</pre>

            <h3>Callback</h3>
            <p>onLoad callback is useful to initialize the content when it becomes visible on scroll such as loading data.</p>
            
<pre>
<code class="language-markup" pCode ngNonBindable>
&lt;div pDefer (onLoad)="initData()"&gt;
    &lt;ng-template&gt;
        &lt;p-dataTable [value]="cars"&gt;
            &lt;p-column field="vin" header="Vin"&gt;&lt;/p-column&gt;
            &lt;p-column field="year" header="Year"&gt;&lt;/p-column&gt;
            &lt;p-column field="brand" header="Brand"&gt;&lt;/p-column&gt;
            &lt;p-column field="color" header="Color"&gt;&lt;/p-column&gt;
        &lt;/p-dataTable&gt;
    &lt;/ng-template&gt;
&lt;/div&gt;
</code>
</pre>

<pre>
<code class="language-typescript" pCode ngNonBindable>
this.cars = //initialize
</code>
</pre>
            
            <h3>Properties</h3>
            <p>Directive has no attributes.</p>
            
            <h3>Events</h3>
            <div class="doc-tablewrapper">
                <table class="doc-table">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Parameters</th>
                            <th>Description</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>onLoad</td>
                            <td>-</td>
                            <td>Callback to invoke when deferred content is loaded.</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <h3>Styling</h3>
            <p>Directive does not apply any styling to host.</p>

            <h3>Dependencies</h3>
            <p>None.</p>
        </p-tabPanel>
        
        <p-tabPanel header="Source">
            <a href="https://github.com/primefaces/primeng/tree/master/src/app/showcase/components/defer" class="btn-viewsource" target="_blank">
                <i class="fa fa-github"></i>
                <span>View on GitHub</span>
            </a>
<pre>
<code class="language-markup" pCode ngNonBindable>
&lt;div pDefer (onLoad)="initData()"&gt;
    &lt;ng-template&gt;
        &lt;p-dataTable [value]="cars"&gt;
            &lt;p-column field="vin" header="Vin"&gt;&lt;/p-column&gt;
            &lt;p-column field="year" header="Year"&gt;&lt;/p-column&gt;
            &lt;p-column field="brand" header="Brand"&gt;&lt;/p-column&gt;
            &lt;p-column field="color" header="Color"&gt;&lt;/p-column&gt;
        &lt;/p-dataTable&gt;
    &lt;/ng-template&gt;
&lt;/div&gt;
</code>
</pre>


<pre>
<code class="language-typescript" pCode ngNonBindable>
export class DeferDemo &#123;

    cars: Car[];
    
    msgs: Message[] = [];
            
    constructor(private carService: CarService)  &#123;&#125;
    
    initData()  &#123;
        this.msgs = [&#123;severity:'success', summary:'Data Initialized', detail:'Render Completed'&#125;];
        this.carService.getCarsSmall().then(cars => this.cars = cars);
     &#125;
 &#125;
</code>
</pre>

        </p-tabPanel>
     </p-tabView>
</div>
